package com.geek.javase.ch17.videodemo.udp;

import java.io.IOException;
import java.net.*;

/*
 *@Date 2025/11/6
 *@Author wangpeng
 *@Description 发送端
 */
public class UDPSend {
    public static void main(String[] args) {
        String str = "我是UDPSend！";
        byte[] bytes = str.getBytes();
        try {
            //DatagramPacket(byte[] buf, int length, InetAddress address, int port)
            DatagramPacket dp = new DatagramPacket(bytes, bytes.length, InetAddress.getLocalHost(),8899);
            //DatagramSocket send(DatagramPacket dp) 发送数据包
            DatagramSocket ds = new DatagramSocket();
            ds.send(dp);
            //关闭操作
            ds.close();
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
        catch (SocketException e) {
            e.printStackTrace();
        }catch (IOException e) {
            e.printStackTrace();
        }
    }
}
